'use strict';

const { Controller } = require('egg');

class HomeController extends Controller {
  async index () {
    const { ctx } = this;
    ctx.body = 'hi, egg';
  }
  async delete () {
    const { ctx } = this;
    const queries = ctx.queries;
    const deleteinfo = ctx.service.user.deleteById(queries.id);
    console.log(queries);
    ctx.body = deleteinfo;
  }


  async login () {
    const { ctx } = this;
    // ctx.request.body  post的参数
    const data = ctx.request.body;
    console.log(data, "login参数");
    // 查询数据库
    // const _ctx = this.ctx;
    // const user = await _ctx.model.User.findAll();
    // _ctx.body = user;
    console.log(data.username, "username")
    if (data.username == 'admin')
      console.log("ctx.body", ctx.body);
    ctx.body = { code: 0, data: { "token": data.username } };
    console.log("ctx.body", ctx.body);
    // ctx.body = {
    //   "code": 0, "data": { "token": data.username }
    // }
    // 业务处理
    // 业务处理
    // 业务处理
  }

  async user () {
    const { ctx } = this;
    ctx.body = {
      code: 0, data: { "id": 1, "name": "旧味清欢(admin)", "avatar": "https://assets.qszone.com/images/avatar.jpg", "email": "Ronnie@123.com", "role": ["admin"] }
    };
  }
}

module.exports = HomeController;
